package com.xinqi.modules.sys.dict.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.sys.dict.dto.req.DictVersionQueryDTO;
import com.xinqi.modules.sys.dict.dto.rsp.DictGradeResultDTO;
import com.xinqi.modules.sys.dict.dto.rsp.DictStageResultDTO;
import com.xinqi.modules.sys.dict.dto.rsp.DictSubjectResultDTO;
import com.xinqi.modules.sys.dict.dto.rsp.DictVersionResultDTO;
import com.xinqi.modules.sys.dict.service.DictGradeService;
import com.xinqi.modules.sys.dict.service.DictStageService;
import com.xinqi.modules.sys.dict.service.DictVersionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 字典-版本APP控制层
 *
 * @author: linkai
 * @date: 2023/05/07
 */
@Tag(name = "App-系统字典", description = "系统字典App接口")
@RestController
@RequestMapping("/app/dict-version")
@RequiredArgsConstructor
public class DictVersionAppController {

    private final DictVersionService dictVersionService;

    private final DictStageService dictStageService;

    private final DictGradeService dictGradeService;

    /**
     * 字典-版本-分页
     */
    @Operation(summary = "字典-版本-分页")
    @GetMapping("/page")
    public R<PageInfo<DictVersionResultDTO>> page(@ParameterObject DictVersionQueryDTO dto) {
        PageInfo<DictVersionResultDTO> page = dictVersionService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 字典-版本-详情
     */
    @Operation(summary = "字典-版本-详情")
    @GetMapping("/{id}")
    public R<DictVersionResultDTO> findById(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        DictVersionResultDTO dto = dictVersionService.findById(id);
        return R.data(dto);
    }

    @Operation(summary = "查询版本中的学段")
    @GetMapping("/{id}/stage")
    public R<List<DictStageResultDTO>> findStageByVersionId(@PathVariable("id") Long id) {
        List<DictStageResultDTO> list = dictVersionService.findStageByVersionId(id);
        return R.data(list);
    }

    @Operation(summary = "查询版本中的年级")
    @GetMapping("/{id}/grade")
    public R<List<DictGradeResultDTO>> findGradeByVersionId(@PathVariable("id") Long id) {
        return R.data(dictStageService.findGradeByVersionId(id));
    }

    @Operation(summary = "查询版本中的学科")
    @GetMapping("/{id}/Subject")
    public R<List<DictSubjectResultDTO>> findSubjectByVersionId(@PathVariable("id") Long id) {
        return R.data(dictGradeService.findSubjectByVersionId(id));
    }

}
